package reno.market.mainmarket.rivenmarket.controller;

import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import reno.market.mainmarket.common.JSONUtils;
import reno.market.mainmarket.common.ResponseMO;
import reno.market.mainmarket.rivenmarket.mo.RivenMarketMO;
import reno.market.mainmarket.rivenmarket.service.RivenMarketService;

import java.util.List;
import java.util.Map;

@RestController
public class RivenMarketController {

    @Autowired
    RivenMarketService rivenMarketService;

    @RequestMapping(value = "/getRivenMarket")
    public JSONObject getRivenMarket(@RequestParam(name = "weaponCn") String weaponCn) {
        Map<String, String> weaponInfo = rivenMarketService.findWeaponInfo(weaponCn);
        ResponseMO responseMO = new ResponseMO();
        if (weaponInfo != null) {
            String weaponName = weaponInfo.get("weaponEn");
            String other = weaponInfo.get("other");
            List<RivenMarketMO> rivenMarketMOList = rivenMarketService.getResult(weaponName);
            String sendMsg;
            if (null != rivenMarketMOList) {
                sendMsg = rivenMarketService.explain(rivenMarketMOList, weaponCn);
            } else {
                sendMsg = "暂无此武器裂罅出售或服务器连接超时，请稍后重试。";
            }
            responseMO.setResponseString0(sendMsg);
            responseMO.setResponseString1(other);
            return JSONUtils.success(responseMO);
        } else {
            responseMO.setResponseString0("未查询到该武器名称，请检查后重试");
            return JSONUtils.failure(responseMO);
        }
    }


}
